package com.eboss2.sbs.activity;

import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.eboss2.sbs.R;
import com.eboss2.sbs.activity.base.BaseActivity;
import com.eboss2.sbs.config.Config;
import com.eboss2.sbs.http.HttpUtil;
import com.eboss2.sbs.model.VerificationDetailsInfo;
import com.eboss2.sbs.myapplication.MyApplication;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.loopj.android.http.RequestParams;
import com.mytools.tool.activityManager.MyActivityManager;
import com.tool.utils.utils.StringUtils;
import com.tool.utils.utils.ToastUtils;

import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class VerificationDetailActivity extends BaseActivity {

    private static final String TAG = "TxRecordDetailActivity";
    @BindView(R.id.titleback_btn_back)
    LinearLayout titlebackBtnBack;
    @BindView(R.id.tv_amount)
    TextView tvAmount;
    @BindView(R.id.tv_status)
    TextView tvStatus;
    @BindView(R.id.tv_goods_name)
    TextView tvGoodsName;
    @BindView(R.id.tv_member_name)
    TextView tvMemberName;
    @BindView(R.id.tv_member_id)
    TextView tvMemberId;
    @BindView(R.id.tv_sale_count)
    TextView tvSaleCount;
    @BindView(R.id.tv_pay_time)
    TextView tvPayTime;
    @BindView(R.id.tv_order_no)
    TextView tvOrderNo;
    @BindView(R.id.tv_order_amt)
    TextView tvOrderAmt;
    @BindView(R.id.tv_coupon)
    TextView tvCoupon;
    @BindView(R.id.tv_settle_amt)
    TextView tvSettleAmt;
    @BindView(R.id.tv_couponCode)
    TextView tvCouponCode;


    private long id;
    private long memberId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(R.layout.activity_verification_detail);
        ButterKnife.bind(this);
        MyActivityManager.getInstance().addActivity(this);
        initView();

        id = getIntent().getLongExtra("id", 0);
        memberId = getIntent().getLongExtra("memberId", 0);
        if (id != 0) {
            getdata();
        }
    }

    private void initView() {
        RelativeLayout relativeLayout = relativeLayout(R.id.lv_heard);
        relativeLayout.setBackgroundColor(getResources().getColor(R.color.statusBar));
        showView(R.id.titleback_btn_back, true);
        setTvText(R.id.tv_title, "核销详情 ");


    }


    @OnClick(R.id.titleback_btn_back)
    public void onViewClicked() {
        finish();
    }


    private void getdata() {

        showProgress("加载中...");
        RequestParams params = new RequestParams();
        params.put("id", id);
        params.put("memberId", memberId);
        params.put("shopId", MyApplication.getmInstance().getLoginMEntity().getShopid());
        HttpUtil.get(Config.SBS_VERIFICATION, params, new HttpUtil.RequestListener() {
            @Override
            public void success(String response) {
                disShowProgress();
                try {
                    JSONObject result = new JSONObject(response);

                    if (!result.optBoolean("status")) {
                        ToastUtils.CustomShow(mContext, result.optString("message"));
                    } else {
                        VerificationDetailsInfo txRecordDetail = new Gson().fromJson(result.optString("data"), new TypeToken<VerificationDetailsInfo>() {
                        }.getType());
                        if (txRecordDetail != null) {
                            tvAmount.setText(StringUtils.formatIntMoney(txRecordDetail.getRealAmount()));
                            tvStatus.setText(txRecordDetail.getCouponStatus());
                            tvGoodsName.setText(txRecordDetail.getGoodName());
                            tvMemberName.setText(txRecordDetail.getMemberName());
                            tvMemberId.setText(txRecordDetail.getCardNo());
                            tvSaleCount.setText(txRecordDetail.getCount() + "");
                            tvPayTime.setText(txRecordDetail.getVerifyTime());
                            tvOrderNo.setText(txRecordDetail.getOrderNo());
                            tvOrderAmt.setText(StringUtils.formatIntMoney(txRecordDetail.getPrice()));
                            tvCoupon.setText(StringUtils.formatIntMoney(txRecordDetail.getDiscountAmount()) + "元");
                            tvSettleAmt.setText(StringUtils.formatIntMoney(txRecordDetail.getSettingPrice()) + "元");
                            tvCouponCode.setText(txRecordDetail.getCouponCode());
                        }
                    }
                } catch (Exception e) {
                    Log.e(TAG, "doLogin() Exception: " + e.getMessage());
                }


            }

            @Override
            public void failed(Throwable error) {
                disShowProgress();
                showE404();
            }
        });
    }

}
